package com.weme.common.util

import android.content.Context
import androidx.media3.common.MediaItem
import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.exoplayer.SimpleExoPlayer

class CustomExoPlayerManager(private val context: Context) {
    private var exoPlayer: ExoPlayer? = null

    init {
        exoPlayer = ExoPlayer.Builder(context).build()
    }

    fun prepareMedia(mediaUri: String) {
        val mediaItem = MediaItem.fromUri(mediaUri)
        exoPlayer?.setMediaItem(mediaItem)
        exoPlayer?.prepare()
    }

    fun play() {
        exoPlayer?.playWhenReady = true
    }

    fun pause() {
        exoPlayer?.pause()
    }

    fun stop() {
        exoPlayer?.playWhenReady = false
    }

    fun release() {
        exoPlayer?.release()
    }

    fun getCurrentPosition(): Long {
        return exoPlayer?.currentPosition ?: 0
    }

    fun getDuration(): Long {
        return exoPlayer?.duration ?: 0
    }

    fun isPlaying(): Boolean {
        return exoPlayer?.isPlaying ?: false
    }
}
